package com.mb.app.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.dao.TbShipCfgMapper;
import com.mb.app.domain.TbShipCfg;
import com.mb.app.service.ITbShipCfgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 物流快递配置  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-04-01
 */
@Service
@Slf4j
public class TbShipCfgServiceImpl extends ServiceImpl<TbShipCfgMapper, TbShipCfg> implements ITbShipCfgService {

    @Override
    public List<TbShipCfg> queryList(Map<String, Object> map) {
        List<TbShipCfg> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbShipCfg TbShipCfg) {
        TbShipCfg.setCreateTime(new Date());
        return this.baseMapper.insert(TbShipCfg);
    }

    @Override
    public int update(TbShipCfg TbShipCfg) {
        try {
            TbShipCfg TbShipCfg1 = new TbShipCfg();
            TbShipCfg1.setShipId(TbShipCfg.getShipId());
            TbShipCfg1.setDataStatus(1);
            TbShipCfg TbShipCfgDO = this.baseMapper.selectOne(TbShipCfg1);
            if(TbShipCfgDO != null){
                TbShipCfg.setUpdateTime(new Date());
                this.baseMapper.updateById(TbShipCfg);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }


    @Override
    public int remove(Long shipId,Long delUserId) {
//        return this.baseMapper.deleteById(appId);
        TbShipCfg TbShipCfg = new TbShipCfg();
        TbShipCfg.setShipId(shipId);
        TbShipCfg.setDeleteTime(new Date());
        TbShipCfg.setDataStatus(0);
        TbShipCfg.setDeleteUserId(delUserId);
        return this.baseMapper.updateById(TbShipCfg);
    }

    @Override
    public TbShipCfg getDtl(Long bannerId) {
        TbShipCfg TbShipCfg = this.baseMapper.selectById(bannerId);
        return TbShipCfg;
    }

    @Override
    public boolean shipCfgsNameExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByShipCfgInfo(params).size() > 0;
        return exit;
    }

    @Override
    public List<TbShipCfg> selectAll() {
        return this.baseMapper.selectAll();
    }

}
